package com.changgou.order.listener;

import com.changgou.order.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 支付成功业务处理监听器
 */
@RabbitListener(queues = "order_pay")
@Component
public class PaySuccessListener {

    @Autowired
    private OrderService orderService;

    @RabbitHandler
    public void messageHandler(Map<String, String> paramMap) {
        //1. 接收订单id, 和交易流水号
        String out_trade_no = paramMap.get("out_trade_no");
        String transaction_id = paramMap.get("transaction_id");

        //2. 调用service支付成功业务处理方法进行处理
        orderService.paySuccess(out_trade_no, transaction_id);
    }
}
